package leetcode.leetcode_hot100;

public class T0019 {
    class Solution{
        public ListNode deleteNode(ListNode head, int n){
            if(head == null){
                return null;
            }
            ListNode dummy = new ListNode(0);
            dummy.next=head;
            ListNode pre=dummy;
            ListNode cur =head;
            while(cur!=null){
                if(cur.val==n){
                    pre.next=cur.next;
                    break;
                }
                pre=cur;
                cur=cur.next;
            }
            return dummy.next;
        }
    }

    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
